package XueHaoYan.rbac.domain.service;

import XueHaoYan.rbac.domain.dto.DeptDto;
import XueHaoYan.rbac.domain.entity.Dept;
import XueHaoYan.rbac.domain.vo.Result;

public class DeptService {

    public static Dept[] data=new Dept[101];

    public static int idCounter = 1; // 0个用法

    public static Result create(DeptDto dto){
        if (idCounter > 100) {
            return Result.failure("创建失败，超出了存储容量");
        }
        Dept dept = new Dept(dto.name, dto.phone);
        dept.id = idCounter++;
        data[dept.id] = dept;
        return Result.success("创建成功！", dept);

    }


    public static Result update(DeptDto dto, int id) {
        if (id < 1 || id >= idCounter || data[id] == null) {
            return Result.failure("更新失败, 不存在该数据");
        }
        Dept dept = data[id];
        dept.name = dto.name;
        dept.phone = dto.phone;
        return Result.success( message: "更新成功", data: null);
    }

    public static Result delete(int id) {
        if (id < 1 || id >= idCounter || data[id] == null) {
            return Result.failure("删除失败, 不存在该数据");
        }
        data[id] = null;
        return Result.success( message: "删除成功", data: null);
    }


}
